from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import os
def getContentOfFile(relpath):
 path = os.path.join(os.path.dirname(__file__), relpath)
 f = open(path,'r')
 fileContents = f.read()
 f.close
 return fileContents
 
 
class Boards(webapp.RequestHandler):
 def get(self):
  boardsXml = getContentOfFile('/testcases/boards.xml')
 self.response.out.write(boardsXml)
 
 def post(self):
if 'HTTP_AUTHORIZATION' in os.environ: #pretend we created a board
self.response.set_status(201)
newlyCreatedResourceUrl = 'http://localhost/boards/12'
self.response.headers['Location'] = newlyCreatedResourceUrl
self.response.out.write(newlyCreatedResourceUrl)
else:
  self.response.headers['WWW-Authenticate'] = 'Basic realm="Go"'
self.response.set_status(401)
application = webapp.WSGIApplication([('/boards/', Boards),])

def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()